

#ifndef UPDATE_DEAL_HTTP_POST_DETAILS_H
#define UPDATE_DEAL_HTTP_POST_DETAILS_H

#include <QObject>
#include <QJsonObject>
#include <QJsonDocument>
#include <QCryptographicHash>
#include "http_support.h"
/**********************************************************
 * this class is for deal http Post Back Data
 */
class DealHttpPostDetails : public QObject {
    typedef void(DealHttpPostDetails::*SignalFunction)(const QByteArray &);

Q_OBJECT
public:
    explicit DealHttpPostDetails(QObject *parent = nullptr);

    ~DealHttpPostDetails() override = default;

    void versionCheck();

    void getGoods();

    static DealHttpPostDetails &instance();

    /**
     * @brief: 处理post返回信息
     * @author:Turbo
     * @param: url  post的地址  postMD5 地址和入参加密之后的值  data 返回的数据
     * @return:
    **/
    void DealPostBackData(const QString &url, const QString &postMD5, const QByteArray &data);

    /**
     * @brief: 处理get返回信息
     * @author:Turbo
     * @param: url  post的地址   data 返回的数据
     * @return:
    **/
    void DealGetBackData(QString url, QByteArray data);

    /**
     * @brief: 获取广告信息
     * @author:Turbo
     * @return:
    **/
    void Advertisement();

    /**
     * @brief: 获取图片新闻信息
     * @author:Turbo
     * @return:
    **/
    void getPicNews();

    /**
     * @brief: 获取文字新闻信息
     * @author:Turbo
     * @return:
    **/
    void getTextNews();

signals:

    void signalUpdateVersionCheck(const QJsonArray &obj);

    void signalGoods(const QJsonObject &obj);

    void signalAdvertisement(const QJsonObject &obj);

    void signalPicNews(const QJsonObject &obj);

    void signalTextNews(const QJsonObject &obj);

private:
    void updateCallBack(const QByteArray &data);

    void goodsCallBack(const QByteArray &data);

    void advertisementCallBack(const QByteArray &data);

    void picNewsCallBack(const QByteArray &data);

    void textNewsCallBack(const QByteArray &data);

    static QString GetUrl(const QString &key);

    static SignalFunction GetFunc(const QString &key);

    static QPair<QString, SignalFunction> GetMapValue(const QString &key);
};

#endif //UPDATE_DEAL_HTTP_POST_DETAILS_H
